package wei.xinya.springwebflux;

import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import wei.xinya.springwebflux.entity.User;

public class Client {
    public static void main(String[] args) {
        WebClient webClient = WebClient.create("http://localhost:8090");
        User user = webClient.get().uri("/user/{id}", 1).accept(MediaType.APPLICATION_JSON)
                .retrieve().bodyToMono(User.class).block();

        System.out.println("----------------------------------------------------");
        System.out.println("result::" + user);
        System.out.println("----------------------------------------------------");

        Flux<User> userFlux = webClient.get().uri("/user").accept(MediaType.APPLICATION_JSON)
                .retrieve().bodyToFlux(User.class);

        System.out.println("----------------------------------------------------");
        userFlux.map(User::getName).buffer().doOnNext(System.out::println).blockFirst();
        System.out.println("----------------------------------------------------");

    }
}
